package com.zcx.qshop.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.view.rebound.ReboundListView;
import com.zcx.qshop.QSApplication;
import com.zcx.qshop.R;
import com.zcx.qshop.adapter.SchoolAdapter;
import com.zcx.qshop.conn.JsonAreaAsyGet;
import com.zcx.qshop.conn.JsonSchoolAsyGet;
import com.zcx.qshop.view.TitleView;

/**
 * Created by Administrator on 2015/8/22 0022.
 */
public class SchoolActivity extends QSActivity {

    @BoundView(R.id.title_view) private TitleView titleView;

    @BoundView(R.id.school_list_view) private ReboundListView reboundListView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_school);

        titleView.showStyle(TitleView.Style.FULL);

        titleView.showType(TitleView.Type.BACK_TWO, TitleView.Type.NAME_ONE);

        titleView.setTitleName("切换学校");

        titleView.setOnTitleItemClickListener(new TitleView.OnTitleItemClickListener() {

            @Override
            public void onBackClick() {

                finish();

            }

        });

        final JsonAreaAsyGet.Area area = (JsonAreaAsyGet.Area)getIntent().getSerializableExtra("Area");

        new JsonSchoolAsyGet(area.code, new AsyCallBack<JsonSchoolAsyGet.Info>(){

            @Override
            public void onSuccess(String toast, int type, final JsonSchoolAsyGet.Info info) throws Exception {

                reboundListView.setAdapter(new SchoolAdapter(SchoolActivity.this, reboundListView, info.schools));

                reboundListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

//                        if(ClassifyFragment.onSchoolChangeListener != null){

//                            ClassifyFragment.onSchoolChangeListener.onSchoolChange(area, info.schools.get(position));

                            QSApplication.INSTANCE.finishActivity(CityActivity.class);

//                            if(ShopCarFragment.onShopCarChangeListener != null){
//
//                                ShopCarFragment.onShopCarChangeListener.onShopCarChange();
//
//                            }

//                            finish();

                            return;

//                        }

//                        if(CreateAddressActivity.onAddressChangeListener !=null ){
//
//                            CreateAddressActivity.onAddressChangeListener.onSchollChange(info.schools.get(position));
//
//                            finish();
//
//                            return;
//
//                        }

                    }

                });

            }

        }).execute(this);

    }

}
